#include <iostream>
using namespace std;

struct Student{
	char name[20];
	int id;
	int scores[3];
	int averageScore;
};

void sort(Student s[],int num){
	for(int i = 0;i < num - 1;i++){
		bool change = false;
		for(int j = 0;j < num - i - 1;j++){
			if(s[j].averageScore < s[j+1].averageScore){
				Student temp = s[j];
				s[j] = s[j+1];
				s[j+1] = temp;
				change = true;
			}
		}
		if(!change)
			break;
	}
}

int main(){
	Student s[100];
	int num;
	cout << "Please input the num of Students:" << endl;
	cin >> num;
	cout << "Input name,id,scores:" << endl; 
	for(int i = 0;i < num;i++){
		cin >> s[i].name >> s[i].id >> s[i].scores[0] >> s[i].scores[1] >> s[i].scores[2];
		s[i].averageScore = (s[i].scores[0]+s[i].scores[1]+s[i].scores[2])/3;
	}
	sort(s,num);
	for(int i = 0;i < num; i ++)
		cout << s[i].id << " " << s[i].name << " " << s[i].averageScore << endl;
	system("pause");
}